﻿unit SortByASC;

interface

uses
  Points;
//冒泡升序排序 var引用传递
procedure Sort(var ArrPoint : Array of TPoint);

implementation

procedure Sort(var ArrPoint : Array of TPoint);
var
  I,J : Integer;
  Temp : TPoint;
begin
  for I := Low(ArrPoint) to High(ArrPoint) do
  begin
    for J := Low(ArrPoint) to High(ArrPoint)-I-1 do
    begin
      if((ArrPoint[J].X>ArrPoint[J+1].X) or ((ArrPoint[J].X = ArrPoint[J+1].X) and (ArrPoint[J].Y > ArrPoint[J+1].Y))) then
      begin
        Temp.X := ArrPoint[J].X;
        Temp.Y := ArrPoint[J].Y;
        ArrPoint[J].X := ArrPoint[J+1].X;
        ArrPoint[J].Y := ArrPoint[J+1].Y;
        ArrPoint[J+1].X := Temp.X;
        ArrPoint[J+1].Y := Temp.Y;
      end;
    end;
  end;
end;

end.
